package tp1;

import ca.etsmtl.log.util.IDLogger;
import java.awt.Color;


public abstract class Forme {
    
        public final int FORME_CARR  = 1;
        public final int FORME_RECT  = 2;
        public final int FORME_CRCL  = 3;
        public final int FORME_OVAL  = 4;
        public final int FORME_LIGN  = 5;
        
    
	private int nseq;
	private Color couleur;

	public Color obtenirCouleur() {
		return couleur;
	}

	public int obtenirNseq() {
		return nseq;
	}

	public Forme(int id, Color c) {
		nseq = id;
		couleur = c;
	}

	 
	/**
	 * @param chaineForme La chaine contenant les informations sur la forme
	 * @return Un rectangle ou un ovale ou une ligne. Notez qu'un carr� est un rectangle et qu'un cercle est un ovale. 
	 */
	public static Forme creerForme(String chaineForme) {
		String parts[], type;
		int id;

		System.out.println("chaineForme = " + chaineForme);
		parts = chaineForme.split(" ");

		id = Integer.valueOf(parts[0]);
		IDLogger.getInstance().logID(id);
		type = parts[1].replaceAll("[<>]", "");

		if (type.equals("LIGNE"))/* x1 y1 x2 y2 */
		{
			int x1, x2, y1, y2;
			x1 = Integer.valueOf(parts[2]);
			y1 = Integer.valueOf(parts[3]);
			x2 = Integer.valueOf(parts[4]);
			y2 = Integer.valueOf(parts[5]);

			return new Ligne(id, x1, y1, x2, y2, Color.BLACK);
		} else if (type.equals("CARRE"))/* x1 y1 x2 y2 */
		{
			int x1, x2, y1, y2;
			x1 = Integer.valueOf(parts[2]);
			y1 = Integer.valueOf(parts[3]);
			x2 = Integer.valueOf(parts[4]);
			y2 = Integer.valueOf(parts[5]);

			return new Rectangle(id, x1, y1, x2, y2, Color.RED);
		} else if (type.equals("RECTANGLE"))/* x1 y1 x2 y2 */
		{
			int x1, x2, y1, y2;
			x1 = Integer.valueOf(parts[2]);
			y1 = Integer.valueOf(parts[3]);
			x2 = Integer.valueOf(parts[4]);
			y2 = Integer.valueOf(parts[5]);
			return new Rectangle(id, x1, y1, x2, y2, Color.BLUE);
		} else if (type.equals("CERCLE"))/* x1 y1 r */
		{
			int x1, y1, r;
			x1 = Integer.valueOf(parts[2]);
			y1 = Integer.valueOf(parts[3]);
			r = Integer.valueOf(parts[4]);
			return new Ovale(id, x1, y1, r, Color.YELLOW);
		} else if (type.equals("OVALE"))/* x1 y1 rh rv */
		{
			int x1, y1, rh, rv;
			x1 = Integer.valueOf(parts[2]);
			y1 = Integer.valueOf(parts[3]);
			rh = Integer.valueOf(parts[4]);
			rv = Integer.valueOf(parts[5]);
			return new Ovale(id, x1, y1, rh, rv, Color.GREEN);
		} else {
			return null;
		}
	}
        
        public abstract double calcAire();
        public abstract double calcDistanceMax();
        public abstract int obtenirEntierTypeForme();
        
}
